/* $Header: pi_diag.c,v 2.6 03/11/07 13:49:53 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:                                                        */
/* ============                                                        */
/*                                                                     */
/* Author:                                                             */
/*                                                                     */
/* MODULE PURPOSE:                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/


#include <typedefs.h>
#include <error.h>
#include <p_wkfile.h>
#include <p_status.h>
#include <list_mgmt.h>
#include <pcb_defs.h>
#include <math.h>
#include <keyboard.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/

#include "proto.h"
#include "p_tcomp.h"

/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

INT32 CountsToMilliVolts( U_INT16 counts )

/**end_proto**/

{

    return SignedQuadWordMultiplyDivide( (INT32)counts, 1000, 13107 );

}

/**begin_proto**/

INT32 CountsTo100MicroVolts( U_INT16 counts )

/**end_proto**/

{

    return SignedQuadWordMultiplyDivide( (INT32)counts, 10000, 13107 );

}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

INT32 GetDutyCycleActual ( U_INT8 channel )

/**end_proto**/

{

   if ( channel >= NUM_PNEU_CHANNELS ) return 0;

   return QuadWordMultiplyDivide( Inst_Status.Pneu.Actual_Duty_Cycles[ channel ],
                                  100,
                                  0x7fff );

}


/**begin_proto**/

INT32 GetDutyCycleSetpt ( U_INT16 channel )

/**end_proto**/

{

   if ( channel >= NUM_PNEU_CHANNELS ) return 0;

   return QuadWordMultiplyDivide( Inst_Status.Pneu.Duty_Cycle_Setpts[ channel ],
                                  100,
                                  0x7fff );

}


/**begin_proto**/

UI_ERR SetDutyCycleSetpt ( U_INT8 channel, INT32 duty_cycle )

/**end_proto**/
{

   if ( channel >= NUM_PNEU_CHANNELS ) return INVALID_PARAM;

   Inst_Status.Pneu.Duty_Cycle_Setpts[ channel ] =
               QuadWordMultiplyDivide( duty_cycle, 0x7fff, 100 );


   if ( duty_cycle == 0 )
   {
       if ( !RestartChannel (  1 << channel ) ) return TEST_FAILED;
   }
   else
   {
       WriteDutyCycle ( channel, Inst_Status.Pneu.Duty_Cycle_Setpts [ channel ] );
   }

   return OK;
}




/**begin_proto**/

U_INT16 GetChannelAvgVoltage( U_INT16 channel )

/**end_proto**/

{

   if ( channel < NUM_PNEU_CHANNELS )  return Inst_Status.Pneu.Stable_Volts[ channel ];

   return 0xffff;

}



/**begin_proto**/

U_INT16 GetEnvAvgVoltage( U_INT16 channel )

/**end_proto**/

{

   if ( channel < NUM_ENV_CHANNELS )  return Inst_Status.Pneu.Stable_Env[ channel ];

   return 0xffff;

}



/**begin_proto**/

U_INT16 GetChannelNoise( U_INT16 channel )

/**end_proto**/

{
   if ( channel < NUM_PNEU_CHANNELS ) return Inst_Status.Pneu.MAX_MIN[ channel ];

   return 0xffff;
}



/**begin_proto**/

U_INT16 GetEnvNoise( U_INT16 channel )

/**end_proto**/

{
   if ( channel < NUM_ENV_CHANNELS ) return Inst_Status.Pneu.ENV_MAX_MIN[ channel ];

   return 0xffff;
}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

U_INT32 GetModuleSerialNumber( U_INT8 module )

/**end_proto**/

{

    U_INT16 low_word, high_word;

    if ( module > 4 ) return 0;

    if ( !ReadEeprom( module, SERIAL_NO_HIGH, &high_word ) ||
         !ReadEeprom( module, SERIAL_NO_LOW,  &low_word ) )   return 0;

    return (((U_INT32)high_word) << 16) | low_word;
}


/**begin_proto**/

void    GetModuleBuildDateParts( U_INT8 module, U_INT16 *year, U_INT8 *month, U_INT8 *day )

/**end_proto**/

{
    U_INT16 word;

    word = 0;

    if (module <= 4 )
    {
       if ( ! ReadEeprom( module, BUILD_DATE, &word ) ) word = 0;
    }

    *day   =  word >> 11;
    *month = (word & 0x0780) >> 7;
    *year  = (word & 0x007f) + 80;

}


/**begin_proto**/

U_INT16 GetModuleVersion( U_INT8 module )

/**end_proto**/

{
    U_INT16 word;

    word = 0;

    if ( module > 4 ) return 0;

    (void)ReadEeprom( module, VERSION, &word );

    return word;
}


/**begin_proto**/

U_INT16 GetModuleType( U_INT8 module )

/**end_proto**/

{
    U_INT16 word;

    word = 0;

    if ( module > 4 ) return 0;

    (void)ReadEeprom( module, TYPE, &word );

    return word;
}




/**begin_proto**/

U_INT16  GetTestStationId ( U_INT8 module_number )

/**end_proto**/

{

    U_INT16 station_id;

    station_id = 0;

    (void)ReadEeprom ( module_number, TEST_STATION_ID, &station_id );

    return station_id;
}
/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

U_INT16 GetModuleThermistorVoltage( U_INT16 module )

/**end_proto**/

{

    switch ( module )
    {
       case FRNT_INLET_MODULE_NUMBER:    return Inst_Status.Pneu.Environment.Frnt_Inlet_Temp;
       case BACK_INLET_MODULE_NUMBER:    return Inst_Status.Pneu.Environment.Back_Inlet_Temp;
       case FRNT_DETECTOR_MODULE_NUMBER: return Inst_Status.Pneu.Environment.Frnt_Det_Temp;
       case BACK_DETECTOR_MODULE_NUMBER: return Inst_Status.Pneu.Environment.Back_Det_Temp;
       case PNEU_AUX_MODULE_NUMBER:      return Inst_Status.Pneu.Environment.Aux_Temp;
    }
    return 0;

}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

UI_ERR GetEepromDefinition ( U_INT8 module, U_INT16 address, U_INT16 *value, BIT8 *definition )

/**end_proto**/

{
    UI_ERR error;

    switch ( module )
    {
      case FRNT_INLET_MODULE_NUMBER:

                if ( ( (U_INT16)Inst_Config.Pneu.Frnt_Inlet.Type & 0x00ff ) == (U_INT16)JIB )
                {
                    if ( (error = GetJillEepromDef (address, definition )) != OK ) return error;
                }
                else
                {
                    if ( (error = GetInletEepromDef (address, definition )) != OK ) return error;
                }
                (void)ReadEeprom( module, address, value );
                break;

      case BACK_INLET_MODULE_NUMBER:

                if ( ((U_INT16)Inst_Config.Pneu.Back_Inlet.Type & 0x00ff ) == (U_INT16)JIB )
                {
                    if ( (error = GetJillEepromDef (address, definition )) != OK ) return error;
                }
                else
                {
                    if ( (error = GetInletEepromDef (address, definition )) != OK ) return error;
                }
                (void)ReadEeprom( module, address, value );
                break;

      case FRNT_DETECTOR_MODULE_NUMBER:
      case BACK_DETECTOR_MODULE_NUMBER:

                if ( (error = GetDetEepromDef (address, definition )) != OK )
                {
                   return error;
                }
                (void)ReadEeprom( module, address, value );
                break;

      case PNEU_AUX_MODULE_NUMBER:

                if ( (error = GetAuxEepromDef (address, definition )) != OK )
                {
                   return error;
                }
                (void)ReadEeprom( module, address, value );
                break;

       default: return INVALID_PARAM;

     }

     return OK;

}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT8 GetPcbInletControlMode ( pINLET_STATUS status )

/**end_proto**/
{
    /* values defined in pcb_defs.h */

    /* #define FWD_FLOW_NO_PRES   0 */
    /* #define FWD_FLOW_BACK_PRES 1 */
    /* #define FWD_PRES_NO_FLOW   2 */

    return status->PCB_Inlet_Control_Mode;
}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

U_INT16 GetModuleTemp( U_INT8 module )

/**end_proto**/

{

   /* returns module temp in IU (64thK) */

   switch ( module )
   {
       case FRNT_INLET_MODULE_NUMBER:     return Inst_Status.Pneu.Frnt_Inlet.Tcomp_Tables->Thermistor.Module_Temperature;
       case BACK_INLET_MODULE_NUMBER:     return Inst_Status.Pneu.Back_Inlet.Tcomp_Tables->Thermistor.Module_Temperature;
       case FRNT_DETECTOR_MODULE_NUMBER:  return Inst_Status.Pneu.Frnt_Detector.Tcomp_Tables->Thermistor.Module_Temperature;
       case BACK_DETECTOR_MODULE_NUMBER:  return Inst_Status.Pneu.Back_Detector.Tcomp_Tables->Thermistor.Module_Temperature;
       case PNEU_AUX_MODULE_NUMBER:       return Inst_Status.Pneu.Aux.Tcomp_Tables->Thermistor.Module_Temperature;

       default: return 0;
   }

}





/**begin_proto**/

UI_ERR SetInletPresDutyCycleSetpt( pINLET_STATUS status, INT32 setpt )

/**end_proto**/
{
      return SetDutyCycleSetpt( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 0 ], setpt );
}

/**begin_proto**/

UI_ERR SetInletFlowDutyCycleSetpt( pINLET_STATUS status, INT32 setpt )

/**end_proto**/
{
      return SetDutyCycleSetpt( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 1 ], setpt );
}


/**begin_proto**/

UI_ERR SetDetPresDutyCycleSetpt( pDETECTOR_STATUS status, U_INT8 gas_num, INT32 setpt )

/**end_proto**/
{

      return SetDutyCycleSetpt( Det_Channel_Map[ status->Position== FRNT_DET ? 0 : 1  ] [ gas_num-1 ], setpt );
}

/**begin_proto**/

UI_ERR SetAuxPresDutyCycleSetpt( pAUX_STATUS status, INT32 setpt )

/**end_proto**/
{
      return SetDutyCycleSetpt( Aux_Channel_Map[ status->Position == AUX_3 ? 0 :
                                                 status->Position == AUX_4 ? 1 :
                                                                             2  ], setpt );
}







/**begin_proto**/

INT32 GetInletPresDutyCycleSetpt( pINLET_STATUS status )

/**end_proto**/
{
      return GetDutyCycleSetpt( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 0 ] );
}

/**begin_proto**/

INT32 GetInletFlowDutyCycleSetpt( pINLET_STATUS status )

/**end_proto**/
{
      return GetDutyCycleSetpt( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 1 ] );
}


/**begin_proto**/

INT32 GetDetPresDutyCycleSetpt( pDETECTOR_STATUS status, U_INT8 gas_num )

/**end_proto**/
{

      return GetDutyCycleSetpt( Det_Channel_Map[ status->Position== FRNT_DET ? 0 : 1  ] [ gas_num-1 ] );
}

/**begin_proto**/

INT32 GetAuxPresDutyCycleSetpt( pAUX_STATUS status )

/**end_proto**/
{
      return GetDutyCycleSetpt( Aux_Channel_Map[ status->Position == AUX_3 ? 0 :
                                                 status->Position == AUX_4 ? 1 :
                                                                             2 ] );
}



/**begin_proto**/

INT32 GetInletPresDutyCycleActual( pINLET_STATUS status )

/**end_proto**/
{
      return GetDutyCycleActual( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1][ 0 ] );
}

/**begin_proto**/

INT32 GetInletFlowDutyCycleActual( pINLET_STATUS status )

/**end_proto**/
{
      return GetDutyCycleActual( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 1 ] );
}


/**begin_proto**/

INT32 GetDetPresDutyCycleActual( pDETECTOR_STATUS status, U_INT8 gas_num )

/**end_proto**/
{

      return GetDutyCycleActual( Det_Channel_Map[ status->Position == FRNT_DET ? 0 : 1 ] [ gas_num -1 ] );
}

/**begin_proto**/

INT32 GetAuxPresDutyCycleActual( pAUX_STATUS status )

/**end_proto**/
{
      return GetDutyCycleActual( Aux_Channel_Map[ status->Position == AUX_3 ? 0 :
                                                  status->Position == AUX_4 ? 1 :
                                                                              2 ] );
}







/**begin_proto**/

INT32 GetInletPresAvgVoltage( pINLET_STATUS status )

/**end_proto**/
{
      return CountsToMilliVolts( GetChannelAvgVoltage( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 0 ] ) );
}

/**begin_proto**/

INT32 GetInletFlowAvgVoltage( pINLET_STATUS status )

/**end_proto**/
{
      return CountsToMilliVolts( GetChannelAvgVoltage( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 1 ] ) );
}

/**begin_proto**/

INT32 GetInletGasIdAvgVoltage( pINLET_STATUS status )

/**end_proto**/
{
      return CountsToMilliVolts( GetEnvAvgVoltage( (status->Position == FRNT_INLET ?
                                            FRNT_INLET_GAS_ID_INDEX :
                                            BACK_INLET_GAS_ID_INDEX ) - FIRST_CHANNEL_INDEX ));
}


/**begin_proto**/

INT32 GetDetPresAvgVoltage( pDETECTOR_STATUS status, U_INT8 gas_num )

/**end_proto**/
{

      return CountsToMilliVolts( GetChannelAvgVoltage( Det_Channel_Map[ status->Position == FRNT_DET ? 0 : 1 ] [ gas_num -1 ] ) );
}

/**begin_proto**/

INT32 GetAuxPresAvgVoltage( pAUX_STATUS status )

/**end_proto**/
{
      return CountsToMilliVolts( GetChannelAvgVoltage( Aux_Channel_Map[ status->Position == AUX_3 ? 0 :
                                                                        status->Position == AUX_4 ? 1 :
                                                                                                    2 ] ) );
}

/**begin_proto**/

INT32 GetAuxPresVoltageSetpt( pAUX_STATUS status )

/**end_proto**/
{
    switch ( status->Position )
    {
      case AUX_3: return CountsToMilliVolts( Inst_Status.Pneu.Aux.Tcomp_Tables->Aux_3.Pres_Volts_Setpt );
      case AUX_4: return CountsToMilliVolts( Inst_Status.Pneu.Aux.Tcomp_Tables->Aux_4.Pres_Volts_Setpt );
      case AUX_5: return CountsToMilliVolts( Inst_Status.Pneu.Aux.Tcomp_Tables->Aux_5.Pres_Volts_Setpt );
      default: return 0;
    }
}







/**begin_proto**/

INT32 GetInletPresNoise( pINLET_STATUS status )

/**end_proto**/
{
      return CountsTo100MicroVolts( GetChannelNoise( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 0 ] ) );
}

/**begin_proto**/

INT32 GetInletFlowNoise( pINLET_STATUS status )

/**end_proto**/
{
      return CountsTo100MicroVolts( GetChannelNoise( Inlet_Channel_Map[ status->Position == FRNT_INLET ? 0 : 1 ][ 1 ] ) );
}


/**begin_proto**/

INT32 GetDetPresNoise( pDETECTOR_STATUS status, U_INT8 gas_num )

/**end_proto**/
{

      return CountsTo100MicroVolts( GetChannelNoise( Det_Channel_Map[ status->Position == FRNT_DET ? 0 : 1 ] [ gas_num -1 ] ) );
}

/**begin_proto**/

INT32 GetAuxPresNoise( pAUX_STATUS status )

/**end_proto**/
{
      return CountsTo100MicroVolts( GetChannelNoise( Aux_Channel_Map[ status->Position == AUX_3 ? 0 :
                                                                      status->Position == AUX_4 ? 1 :
                                                                                                  2 ] ) );
}


/**begin_proto**/

INT32 GetInletModuleTemp( pINLET_STATUS status )

/**end_proto**/
{
      /* return rounded temp in oC, one decimal digit */

      return ( 10 * GetModuleTemp( status->Module_Number ) / 64  - 2731 );
}


/**begin_proto**/

INT32 GetDetModuleTemp( pDETECTOR_STATUS status )

/**end_proto**/
{
      /* return rounded temp in oC, one decimal digit */

      return ( 10 * GetModuleTemp( status->Module_Number ) / 64 - 2731 );
}


/**begin_proto**/

INT32 GetAuxModuleTemp( void )

/**end_proto**/
{
      /* return rounded temp in oC, one decimal digit */

      return ( 10 * GetModuleTemp( Inst_Status.Pneu.Aux.Module_Number ) / 64  - 2731 );
}

/**begin_proto**/

INT32 DcGetAtmosphericPressure ( void )

/**end_proto**/
{
     return ConvertPresIuToDcu ( Atmospheric_Pressure.Dcm2_80, 80 );
}



/**begin_proto**/

INT32 GetPneuAdcOffsetVoltage( void )

/**end_proto**/
{
    return CountsToMilliVolts( GetEnvAvgVoltage( PNEU_ADC_OFFSET_INDEX - FIRST_CHANNEL_INDEX ) ) - 55;
}


/**begin_proto**/

INT32 GetPneuAdcOffsetNoise( void )

/**end_proto**/
{
    return CountsTo100MicroVolts( GetEnvNoise( PNEU_ADC_OFFSET_INDEX - FIRST_CHANNEL_INDEX ) );
}


/**begin_proto**/

INT32 GetPneuAdc10VoltVoltage( void )

/**end_proto**/
{
    return QuadWordMultiplyDivide( CountsToMilliVolts( GetEnvAvgVoltage( PNEU_ADC_10V_INDEX - FIRST_CHANNEL_INDEX ) ),
                                   225,
                                   100 );  /* divider on adc drops 10V to 4.444V or 44.4% */
}


/**begin_proto**/

INT32 GetPneuAdc10VoltNoise( void )

/**end_proto**/
{
    return CountsTo100MicroVolts( GetEnvNoise( PNEU_ADC_10V_INDEX - FIRST_CHANNEL_INDEX ) );
}


/**begin_proto**/

INT32 GetPneuAdc24VoltVoltage( void )

/**end_proto**/
{
    return QuadWordMultiplyDivide( CountsToMilliVolts( GetEnvAvgVoltage( PNEU_24V_INDEX - FIRST_CHANNEL_INDEX ) ),
                                   782,
                                   100 );  /* divider on adc drops 24V to 2.11V or 12.5% */
}


/**begin_proto**/

INT32 GetInletModuleSerialNumber ( pINLET_STATUS status )

/**end_proto**/
{
    /* returns an ordinary number */

     return GetModuleSerialNumber ( status->Module_Number );
}

/**begin_proto**/

INT32 GetDetModuleSerialNumber ( pDETECTOR_STATUS status )

/**end_proto**/
{
    /* returns a 4 charcter string (unterminated) as an integer */

     return GetModuleSerialNumber ( status->Module_Number );
}

/**begin_proto**/

INT32 GetAuxModuleSerialNumber ( void )

/**end_proto**/
{
    /* returns a 4 charcter string (unterminated) as an integer */

     return  GetModuleSerialNumber ( Inst_Status.Pneu.Aux.Module_Number );
}










/**begin_proto**/

INT32  GetInletFunctional ( pINLET_STATUS status )

/**end_proto**/
{
   return status->Config->Functional;
}

/**begin_proto**/

INT32  GetDetFunctional ( pDETECTOR_STATUS status )

/**end_proto**/
{
   return status->Config->Functional;
}

/**begin_proto**/

INT32  GetAuxFunctional ( pAUX_STATUS status )

/**end_proto**/
{
   return status->Config->Functional;
}


/**begin_proto**/

INT32 GetInletColFlowNTP ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertFlowIuToDisplay( status->Ntp_Column, status->IU_Scaling );
}

/**begin_proto**/

INT32 GetInletPurgeFlowNTP ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertFlowIuToDisplay( status->Septum, status->IU_Scaling );
}

/**begin_proto**/

INT32 GetInletSplitFlowNTP ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertFlowIuToDisplay( status->Ntp_Split, status->IU_Scaling );
}

/**begin_proto**/

INT32 GetInletTotalFlowNTP ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertFlowIuToDisplay( status->Ntp_Total, status->IU_Scaling );
}





/**begin_proto**/

INT32 DcGetInletColFlowNTP ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertFlowIuToDcu( status->Ntp_Column, status->IU_Scaling );
}

/**begin_proto**/

INT32 DcGetInletPurgeFlowNTP ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertFlowIuToDcu( status->Septum, status->IU_Scaling );
}

/**begin_proto**/

INT32 DcGetInletSplitFlowNTP ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertFlowIuToDcu( status->Ntp_Split, status->IU_Scaling );
}

/**begin_proto**/

INT32 DcGetInletTotalFlowNTP ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertFlowIuToDcu( status->Ntp_Total, status->IU_Scaling );
}





/**begin_proto**/

INT32 GetInletPresRange ( pINLET_STATUS status )

/**end_proto**/
{
   return ConvertPresIuToDisplay( status->P_Sensor_Range, status->Dcm2_Per_IU );
}

/**begin_proto**/

INT32 GetDetPresRange ( pDETECTOR_STATUS status, U_INT8 gas_num )

/**end_proto**/
{
   switch ( gas_num )
   {
       case 1: return ConvertPresIuToDisplay( status->Gas_1.P_Sensor_Range, status->Gas_1.Dcm2_Per_IU );
       case 2: return ConvertPresIuToDisplay( status->Gas_2.P_Sensor_Range, status->Gas_2.Dcm2_Per_IU );
       case 3: return ConvertPresIuToDisplay( status->Gas_3.P_Sensor_Range, status->Gas_3.Dcm2_Per_IU );
   }

   return 0;
}


/**begin_proto**/

INT32 GetAuxPresRange ( pAUX_STATUS status )

/**end_proto**/
{
       return ConvertPresIuToDisplay( status->P_Sensor_Range, status->Dcm2_Per_IU );
}







/**begin_proto**/

INT32 CalcPredictedPsOffsetIu( pPRES_SENSOR_STRUCT sensor, U_INT16 module_temp )

/**end_proto**/
{
    INT16 delta_T;

    delta_T = ( module_temp - (U_INT16)TCOMP_STD_TEMP_IU );

    return sensor->Parms.Offset + delta_T * sensor->Parms.dOffset_dT / PS_dT_SCALING;
}


/**begin_proto**/

INT32 CalcPredictedPsOffset( pPRES_SENSOR_STRUCT sensor, U_INT16 module_temp, INT16 calib_offset )

/**end_proto**/
{

    return CountsToMilliVolts( CalcPredictedPsOffsetIu( sensor, module_temp ) + calib_offset );

}





/**begin_proto**/

INT32 GetInletPredictedPsOffset( pINLET_STATUS status )

/**end_proto**/
{
    return CalcPredictedPsOffset( &status->Tcomp_Tables->Pres_Sensor,
                                  status->Tcomp_Tables->Thermistor.Module_Temperature,
                                  status->Calib.P_Sensor_Offset  );
}


/**begin_proto**/


INT32 GetInletPredictedFsOffsetIu( pFLOW_SENSOR_STRUCT sensor, U_INT16 module_temp )

/**end_proto**/
{
    INT16 delta_T;

    delta_T = ( module_temp - (U_INT16)TCOMP_STD_TEMP_IU );

    return ( sensor->Parms.Offset + /*  sensor->Parms.Offset_Offset +  */
             (INT32)delta_T * sensor->Parms.delta_offset_delta_t/FS_DOFFSET_SCALING );
}

/**begin_proto**/

INT32 GetInletPredictedFsOffset( pINLET_STATUS status )

/**end_proto**/
{
      return CountsToMilliVolts( GetInletPredictedFsOffsetIu( &status->Tcomp_Tables->Flow_Sensor,
                                                              status->Tcomp_Tables->Thermistor.Module_Temperature)
                                 + status->Calib.F_Sensor_Offset );

}

/**begin_proto**/

INT32 GetDetPredictedPsOffset( pDETECTOR_STATUS status, U_INT8 gas_num )

/**end_proto**/
{
     switch ( gas_num )
     {
        case 1: return CalcPredictedPsOffset( &status->Tcomp_Tables->Fuel.Pres_Sensor,
                                               status->Tcomp_Tables->Thermistor.Module_Temperature,
                                               status->Gas_1.Calib.Offset  );
        case 2: return CalcPredictedPsOffset( &status->Tcomp_Tables->Util.Pres_Sensor,
                                               status->Tcomp_Tables->Thermistor.Module_Temperature,
                                               status->Gas_2.Calib.Offset  );
        case 3: return CalcPredictedPsOffset( &status->Tcomp_Tables->Mug.Pres_Sensor,
                                               status->Tcomp_Tables->Thermistor.Module_Temperature,
                                               status->Gas_3.Calib.Offset  );
     }

     return 0;
}

/**begin_proto**/

INT32 GetAuxPredictedPsOffset( pAUX_STATUS status )

/**end_proto**/
{
     switch ( status->Position )
     {
        case AUX_3: return CalcPredictedPsOffset( &Inst_Status.Pneu.Aux.Tcomp_Tables->Aux_3,
                                                   Inst_Status.Pneu.Aux.Tcomp_Tables->Thermistor.Module_Temperature,
                                                   status->Calib.Offset );
        case AUX_4: return CalcPredictedPsOffset( &Inst_Status.Pneu.Aux.Tcomp_Tables->Aux_4,
                                                   Inst_Status.Pneu.Aux.Tcomp_Tables->Thermistor.Module_Temperature,
                                                   status->Calib.Offset );
        case AUX_5: return CalcPredictedPsOffset( &Inst_Status.Pneu.Aux.Tcomp_Tables->Aux_5,
                                                   Inst_Status.Pneu.Aux.Tcomp_Tables->Thermistor.Module_Temperature,
                                                   status->Calib.Offset );
     }

     return 0;
}





/**begin_proto**/

BIT8 PcbIsAlive()

/**end_proto**/
{
   /* both 331 pneumatics and the pcb must be up to have functioning pneumatics */

    return Inst_Status.Pneu.Pneu_Alive && Inst_Status.Pneu.Pneu_Dsp_Alive;
}

/**begin_proto**/

BIT8 IsSomethingThere( U_INT16 module )

/**end_proto**/
{
   /* returns true if a module is plugged into the pcb or dirtball pcb */

   switch ( module )
   {
      case FRNT_INLET_MODULE_NUMBER:   return Inst_Status.Pneu.Frnt_Inlet.Something_There;
      case BACK_INLET_MODULE_NUMBER:   return Inst_Status.Pneu.Back_Inlet.Something_There;
      case FRNT_DETECTOR_MODULE_NUMBER:return Inst_Status.Pneu.Frnt_Detector.Something_There;
      case BACK_DETECTOR_MODULE_NUMBER:return Inst_Status.Pneu.Back_Detector.Something_There;
      case PNEU_AUX_MODULE_NUMBER:     return Inst_Status.Pneu.Aux.Something_There;
      default:                         return FALSE;
   }
}
